/* eslint-disable react/prop-types */
import React from 'react';
import { withRouter } from 'react-router-dom';
import { Menu, Icon } from 'antd';
import { NavLink } from 'react-router-dom';

const { SubMenu } = Menu;
class MenuList extends React.Component {
    constructor(props) {
        super(props)
        this.state = {

        }
    }

    componentDidMount() {
        //dom操作放在这里面  请求数据也建议放在这里
    }

    render() {
        const path = this.props.location.pathname.substr(1)
        let array = path.split('/') || [];
        let selectKey;
        let openKey;
        if (array.length == 1) {
            selectKey = array[0]
        } else if (array.length >= 2) {
            openKey = array[0];
            selectKey = array[1];
        }
        return (
            <Menu
                defaultSelectedKeys={[selectKey]}
                defaultOpenKeys={[openKey]}
                mode="inline"
                theme="dark"
                style={{paddingBottom: '60px'}}
            >
                <Menu.Item key="index">
                    <NavLink to="/index">
                        <Icon type="home" />
                        <span>首页</span>
                    </NavLink>
                </Menu.Item>
                <SubMenu
                    key="system"
                    title={
                        <span>
                            <Icon type="global" />
                            <span>系统管理</span>
                        </span>
                    }
                >
                    <Menu.Item key="user"><NavLink to="/system/user">用户管理</NavLink></Menu.Item>
                    <Menu.Item key="struct"><NavLink to="/system/struct">组织机构</NavLink></Menu.Item>
                    <Menu.Item key="role"><NavLink to="/system/role">角色管理</NavLink></Menu.Item>
                    <Menu.Item key="menu"><NavLink to="/system/menu">菜单管理</NavLink></Menu.Item>
                    <Menu.Item key="task"><NavLink to="/system/task">定时任务</NavLink></Menu.Item>
                    <Menu.Item key="logger"><NavLink to="/system/logger">系统日志</NavLink></Menu.Item>
                    <Menu.Item key="dict"><NavLink to="/system/dict">字典管理</NavLink></Menu.Item>
                </SubMenu>
                <SubMenu
                    key="tools"
                    title={
                        <span>
                            <Icon type="solution" />
                            <span>开发工具</span>
                        </span>
                    }
                >
                    <Menu.Item key="example"><NavLink to="/tools/example">示例管理</NavLink></Menu.Item>
                    <Menu.Item key="plugin"><NavLink to="/tools/plugin">插件管理</NavLink></Menu.Item>
                    <Menu.Item key="docs"><NavLink to="/tools/docs">文档管理</NavLink></Menu.Item>
                </SubMenu>
            </Menu>
        )
    }
}

export default withRouter(MenuList);
